package com.mooer.app;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mooer.R;
import com.mooer.bean.Shop;
import com.mooer.utils.ui.UiUtils;

/**
 * @author pengfei.xu
 * @version 创建时间：2011-6-19 上午09:17:35 类说明
 */
public class BusinessAdapter extends BaseAdapter {

	private Context ctx;

	private List<Shop> shops;

	public BusinessAdapter(Context ctx, List<Shop> shops) {
		this.ctx = ctx;
		this.shops = shops;
	}

	@Override
	public int getCount() {
		return shops.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View paramView, ViewGroup paramViewGroup) {
		Shop shop = shops.get(position);
		LinearLayout itemView = (LinearLayout) LayoutInflater.from(ctx)
				.inflate(R.layout.business_list_item, null);
		TextView name = (TextView) itemView.findViewById(R.id.name);
		ImageView icon = (ImageView) itemView.findViewById(R.id.icon);
		ImageView youhuiquan = (ImageView) itemView.findViewById(R.id.coupon);
		ImageView star = (ImageView) itemView.findViewById(R.id.star);
		TextView type = (TextView) itemView.findViewById(R.id.type);
		TextView zifei = (TextView) itemView.findViewById(R.id.zifei);
		TextView rigion = (TextView) itemView.findViewById(R.id.rigion);

		name.setText(shop.getName());
		type.setText(shop.getCategoryName());
		if (shop.getAvgConsumption() < 1) {
			zifei.setVisibility(View.GONE);
		} else {
			zifei.setText(ctx.getResources().getString(R.string.zifei_avg,
					shop.getAvgConsumption()));
		}
		rigion.setText(shop.getAddress().getAreaName());
		star.setBackgroundDrawable(UiUtils.selectStar(ctx.getResources(),
				shop.getRating()));
		icon.setImageBitmap(shop.getIcon());
		if (shop.isHasCoupon()) {
			youhuiquan.setBackgroundResource(R.drawable.seller_coupon);
		}

		return itemView;
	}
}
